package com.jiazhong.basic.pack0309;
// 2.实现Comparable
public class Person implements Comparable<Person> {
    private Integer id;
    private String name;
    private Integer age;

    public Person() {
    }

    public Person(Integer id, String name, Integer age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        int myId = this.getId();
        Person it = (Person) obj;
        int itId = it.getId();
        return myId == itId;
    }

    // 3.按照自己要求重写方法
    @Override
    public int compareTo(Person it) {
        // 有自己的要求
        int myAge = this.getAge();
        int itAge = it.getAge();
        return myAge - itAge;
    }
}
